package com.lw.springmvc.controller;

import com.lw.springmvc.excetions.MyBaseException;
import com.lw.springmvc.pojo.User;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/8 17:11
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/test1")
    public String test1(@RequestBody User user){
        System.out.println("收到的数据是===>"+user);
        return "sucess";
    }

    @RequestMapping("/test2")
    public User test2(String username){
        User user=new User();
        user.setUserName("张三");
        user.setPassword("1231566");
        user.setAge(18);
        user.setAddress("北京");
        user.setBirthday(new Date());
        return user;
    }

    @RequestMapping("/test3")
    public String test3(String name){
        Assert.hasLength(name,()->{
            throw new MyBaseException("content empty",-1);
        });
        return "test 3333333333333333";
    }

    @RequestMapping("/test4")
    public String test4(String address){
        Assert.hasLength(address,()->{
            throw new MyBaseException("content empty",-1);
        });
        return "test 3333333333333333";
    }


}
